#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

int main()
{
    int pipefd[2];
    char buf[100];
    int len;

    // 创建匿名管道
    if (pipe(pipefd) == -1)
    {
        perror("make pipe");
        exit(-1);
    }

    pid_t id = fork();
    if (id == 0)
    {
        // child run, 关闭写端
        close(pipefd[1]);
        read(pipefd[0], buf, 100);
        write(1, buf, strlen(buf));
    }
    else
    {
        // father run, 关闭读端
        close(pipefd[0]);

        // 写入
        write(pipefd[1], "i am father\n", 12);
    }
    return 0;
}